<template>
    <div class="user-work" @click="toWork">
        <div class="img">
            <img loading="lazy" v-lazy="props.imgUrl ? imgUrl : require('../assets/某个作品图片.png')" alt="">
        </div>
        <div class="container">
            <div class="content">
                <p class="title">{{ props.title ? props.title : "默认标题" }}</p>
                <p class="des">{{ textDes ? textDes : "一些描述，一些描述，一些描述，一些描述，一些描述，一些描述，一些描述，一些描述" }}</p>
            </div>
            <div class="bottom">
                <!-- <div class="likes-box">
                    <span class="likes-count">{{ props.likes ? count(props.likes) : 0 }}</span>
                    <span class="text">人已点赞</span>
                </div> -->
                <div class="author">
                    {{ props.author ? props.author : "默认作者" }}
                </div>
                <div class="time-box">
                    <span>{{ time }}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
// 将props中的类型定义出来
const props = defineProps({
    workId: {
        type: Number,
        default: 0,
    },
    imgUrl: {
        type: String,
        default: '',
    },
    title: {
        type: String,
        default: '',
    },
    des: {
        type: String,
        default: '',
    },
    author: {
        type: String,
        default: '',
    },
    time: {
        type: String,
        default: '',
    },
    
});
const router = useRouter()
onMounted(() => {
    textDes.value = handleHtmlToText(props.des)
})

const textDes = ref('')
// 将html转换为text
const handleHtmlToText = (html) => {
    const div = document.createElement('div')
    div.innerHTML = html
    return div.innerText
}
const toWork = () => {
    router.push({
        path: '/work-detail/' + props.workId + '/work-introduce'
    })
}
</script>

<style lang="scss">
.user-work {
    width: 250px;
    height: 240px;
    // margin: 50px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 1px #b3b3b3;
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.1s ease-in-out;

    &:hover {
        cursor: pointer;
        transform: scale(1.01);
        box-shadow: 0 0 10px #ccc;
    }

    .img {
        width: 100%;
        height: 140px;

        img {
            width: 100%;
            height: 100%;
        }
    }

    .container {
        width: 100%;
        height: 100px;
        box-sizing: border-box;
        padding: 0 10px;

        .content {
            height: 60px;
            color: #2c3e50;

            .title {
                font-size: 20px;
                margin: 5px 0;
                font-weight: bold;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            .des {
                font-size: 12px;
                color: #9c9c9c;
                overflow: hidden;
                text-overflow: ellipsis;
                // 两行后省略
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;

            }
        }

        .bottom {
            width: 100%;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            color: #2c3e50;

            .author {
                font-size: 16px;
            }

            // .likes-box {

            //     }
            // }
            .bottom{
                width: 100%;
                height: 40px;
                display: flex;
                align-items: center;
                justify-content: center;

                .likes-count {
                    font-size: 16px;
                    font-weight: bold;
                    // color: #666666;
                    margin-right: 2px;
                }

                .text {
                    font-size: 14px;
                    // color: #9c9c9c;
                }

                img {
                    width: 20px;
                    height: 20px;
                }
            }
        }

            .author {
                font-size: 13px;
                // color: #9c9c9c;
            }
        }
    }

</style>